#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;
const int MX = 1e5;

int n, m;
vector<int> e[N];
int st[N][20], dep[N];
void dfs(int u, int fu) {
  st[u][0] = fu;
  dep[u] = dep[fu] + 1;
  for (int v : e[u]) {
    if (v == fu) continue;
    dfs(v, u);
  }
}
void init_st() {
  rep(j, 1, 18) rep(i, 1, n) st[i][j] = st[st[i][j - 1]][j - 1];
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int d = dep[u] - dep[v];
  per(i, 18, 0) {
    if (d & (1 << i)) u = st[u][i];
  }
  if (u == v) return u;
  per(i, 18, 0) {
    if (st[u][i] != st[v][i]) u = st[u][i], v = st[v][i];
  }
  return st[u][0];
}
int mxid[N << 6], mx[N << 6], ch[N << 6][2], tot;
int root[N];
int ans[N];
int newnode(int x) {
  ++tot;
  mxid[tot] = mxid[x];
  mx[tot] = mx[x];
  ch[tot][0] = ch[x][0];
  ch[tot][1] = ch[x][1];
  return tot;
}
void pushup(int p) {
  if (mx[ch[p][0]] >= mx[ch[p][1]])
    mx[p] = mx[ch[p][0]], mxid[p] = mxid[ch[p][0]];
  else
    mx[p] = mx[ch[p][1]], mxid[p] = mxid[ch[p][1]];
}
void update(int pos, int d, int& p, int l, int r) {
  if (p == 0) p = newnode(0);
  if (l == r) {
    mx[p] += d;
    mxid[p] = l;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    update(pos, d, ch[p][0], l, mid);
  else
    update(pos, d, ch[p][1], mid + 1, r);
  pushup(p);
}
void merge(int& p1, int p2, int l, int r) {
  if (!p1 || !p2) {
    p1 = p1 + p2;
    return;
  }
  if (l == r) {
    mx[p1] += mx[p2];
    mxid[p1] = l;
    return;
  }
  int mid = (l + r) >> 1;
  merge(ch[p1][0], ch[p2][0], l, mid);
  merge(ch[p1][1], ch[p2][1], mid + 1, r);
  pushup(p1);
  return;
}
void dfs2(int u, int fu) {
  for (int v : e[u]) {
    if (v == fu) continue;
    dfs2(v, u);
    merge(root[u], root[v], 0, MX);
  }
  ans[u] = mxid[root[u]];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 2, n) {
    int u, v;
    cin >> u >> v;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  dfs(1, 0);
  init_st();
  while (m--) {
    int x, y, z;
    cin >> x >> y >> z;
    int f = lca(x, y);
    int ff = st[f][0];
    update(z, 1, root[x], 0, MX);
    update(z, 1, root[y], 0, MX);
    update(z, -1, root[f], 0, MX);
    if (ff) update(z, -1, root[ff], 0, MX);
  }
  dfs2(1, 0);
  rep(i, 1, n) cout << ans[i] << endl;
  return 0;
}